import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from '@/Layout/index.vue'



Vue.use(VueRouter)

//获取原型上的push函数
const originalPush = VueRouter.prototype.push
// 获取原型对象replace函数
const originalReplace = VueRouter.prototype.replace

// 修改原型对象中的push函数
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

// 修改原型对象中的replace函数
VueRouter.prototype.replace = function replace(location) {
  return originalReplace.call(this, location).catch(err => err)
}


// 路由规则，配置路由
const routes = [
  {
    path: '/',
    //路由重定向，当用户访问根路径时，自动跳转到/login
    redirect: '/login'
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('../views/Login/index.vue')
  },
  {
    path: '/home',
    component: Layout,
    children: [
      {
        path: 'index',
        component: () => import('@/views/Index/index.vue')
      },
      {
        path: 'users',
        component: () => import('@/views/Users/users.vue')
      },
      {
        path: 'review',
        component: () => import('@/views/ReviewWord/review.vue')
      },
      {
        path: 'examine',
        component: () => import('@/views/Examine/examine.vue')
      },
      {
        path: 'discuss',
        component: () => import('@/views/Discuss/discuss.vue')
      },
      {
        path: 'word1',
        component: () => import('@/views/Words/word1.vue')
      },
      {
        path: 'word2',
        component: () => import('@/views/Words/word2.vue')
      }
    ]
  },
  {
    path: '/center',
    name: 'center',
    component: () => import('../views/Center/center.vue')
  }
]


const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})


export default router
